<?php
	/******Function : Warabi User Class******/
	/******Author : Feifei******/
	/******Date : 12/04/2008 ****/
	require_once('class.base.php');

	class appuser extends base{
		function insert_OneUser($name , $pwd , $auth , $nick){
			$name = $this->safePara($name);
			$pwd = $this->safePara($pwd);
			$auth = $this->safePara($auth);
			$nick = $this->safePara($nick);

			$obj = array(
				array("type" => ET_INSERT),
				array(
				"id"=>"",
				"username"=>$name,
				"userpwd"=>$pwd,
				"nickname"=>$nick,
				"auth"=>$auth
				)
			);
			$this->__set("execObj" , $obj);
			$lastid = $this->__insertOneResult();

			$returnstr = array(
				"id" => $lastid,
				"name" => $name,
				"pwd" => $pwd,
				"nick" => $nick,
				"auth" => $auth
			);

			$jsonreturn = json_encode($returnstr);
			echo $jsonreturn;
		}

		function update_OneUser($userid , $language , $password){
			$userid = $this->safePara($userid);
			$language = $this->safePara($language);
			$password = $this->safePara($password);

			$obj = array(
				array("type" => ET_UPDATE),
				array(
					"language" => $language,
					"password" => $password
				),
				array("id" => $userid)
			);
			$this->__set("execObj" , $obj);
			if(!$this->__updateOneResult()){
				echo "fail";
			}
			else echo "succeed";
		}

		function delete_OneUser($userid){
			$userid = $this->safePara($userid);

			$obj = array(
				array("type" => ET_DELETE),
				array("id" => $userid)
			);
			$this->__set("execObj" , $obj);
			if($this->__deleteOneResult())
				echo $userid;
		}

		function get_AllUser_SelectResult($pid , $sname){
			$sname = $this->safePara($sname);
			$scon = empty($sname)?"":"and username like '%".$sname."%'";
			$limit = empty($scon)?("limit ".($pid*PER_NUM)." , ".PER_NUM):"";

			$obj = array(
				array("type" => ET_SELECT),
				array("id" , "username" , "language" , "password" , "lastLogin"),
				array("1"=>"1"),
				array(
					$scon,
					"order by id",
					$limit
				)
			);
			$this->__set("execObj" , $obj);
			return $this->__getAssocResult();
		}

		function get_AllUser_Num(){
			$obj = array(array("type" => ET_COUNT));
			$this->__set("execObj" , $obj);
			return $this->__getTableNum();
		}
	
		

		function showName(){
			return $this->tableName;
		}

	}

	$appuser = new appuser("app_user");

?>